package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import com.haoniu.module.domain.database.RoomUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.UserAdvice;
import com.haoniu.module.service.UserAdviceService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 投诉建议 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-25
 */
@Controller
@RequestMapping("/module/userAdvice")
public class UserAdviceController extends BaseController
{
    private String prefix = "module/userAdvice";

	@Autowired
	private UserAdviceService userAdviceService;

	@RequiresPermissions("module:userAdvice:view")
	@GetMapping()
	public String userAdvice()
	{
	    return prefix + "/userAdvice";
	}

	/**
	 * 查询投诉建议列表
	 */
	@RequiresPermissions("module:userAdvice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserAdvice userAdviceResult) {
		startPage();
        List<UserAdvice> list = userAdviceService.selectUserAdviceList(userAdviceResult);
		for (UserAdvice userAdvice : list) {
			String nickName = userAdvice.getUser().getNickName();
			userAdvice.setNickName(nickName);
			String phone=userAdvice.getUser().getPhone();
			userAdvice.setPhone(phone);
		}
		return getDataTable(list);
	}

	/**
	 * 新增投诉建议
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存投诉建议
	 */
	@RequiresPermissions("module:userAdvice:add")
	@Log(title = "投诉建议", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserAdvice userAdvice) {
        userAdvice.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(userAdviceService.insertUserAdvice(userAdvice));
	}

	/**
	 * 修改投诉建议
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		UserAdvice userAdvice = userAdviceService.selectUserAdviceById(id);
		mmap.put("userAdvice", userAdvice);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存投诉建议
	 */
	@RequiresPermissions("module:userAdvice:edit")
	@Log(title = "投诉建议", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserAdvice userAdvice) {
        userAdvice.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(userAdviceService.updateUserAdvice(userAdvice));
	}

	/**
	 * 删除投诉建议
	 */
	@RequiresPermissions("module:userAdvice:remove")
	@Log(title = "投诉建议", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(userAdviceService.deleteUserAdviceByIds(ids));
	}

}
